﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Net1.My.Web.DAL;
using Net1.My.Web.Models;

namespace Net1.My.Web.Controllers
{
    public class StudentsController : Controller
    {
        private DAL_students ds = new DAL_students();
        /// <summary>
        /// 这是返回列表的视图
        /// </summary>
        /// <returns></returns>
        public IActionResult getStudents()
        {
            return View(ds.getStudents());
        }

        /// <summary>
        /// 这是返回修改表单的视图
        /// </summary>
        /// <returns></returns>
        public IActionResult create()
        {
            return View();
        }
        //添加的方法
        public IActionResult CreateDo(students c)
        {
            if (ds.insertStudents(c) > 0)
            {
                //添加成功
                return Redirect("getStudents");
            }
            else
            {
                //添加失败
                return View("error");
            }
        }
        public IActionResult Edit(int id)
        {
            return View(ds.single(id));
        }
        /// <summary>
        /// 执行修改的方法
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public IActionResult Editdo(students s)
        {
            if (ds.editStudents(s) > 0)
            {
                //操作成功
                return Redirect("getStudents");
            }
            else
            {
                //操作失败
                return View("error");
            }
        }
        public IActionResult Delete(int id)
        {
            if (ds.delStudents(id) > 0)
            {
                //操作成功
                return Redirect("getStudents");
            }
            else
            {
                //操作失败
                return View("error");
            }
        }
        public IActionResult getso(string likestr)
        {
            return View(ds.getso(likestr));
        }
        public IActionResult error()
        {
            return View();
        }
    }
}
